<!DOCTYPE html><html><head>
      <title>YOLO-Face&#x8BAD;&#x7EC3;&#x548C;&#x8C03;&#x7528;&#x6307;&#x5357;</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      
      <link rel="stylesheet" href="file:////home/dworry/.vscode/extensions/shd101wyy.markdown-preview-enhanced-0.6.8/node_modules/@shd101wyy/mume/dependencies/katex/katex.min.css">
      
      
      
      
      
      
      
      
      
      <style>
      /**
 * prism.js Github theme based on GitHub's theme.
 * @author Sam Clarke
 */
code[class*="language-"],
pre[class*="language-"] {
  color: #333;
  background: none;
  font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;
  text-align: left;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  word-wrap: normal;
  line-height: 1.4;

  -moz-tab-size: 8;
  -o-tab-size: 8;
  tab-size: 8;

  -webkit-hyphens: none;
  -moz-hyphens: none;
  -ms-hyphens: none;
  hyphens: none;
}

/* Code blocks */
pre[class*="language-"] {
  padding: .8em;
  overflow: auto;
  /* border: 1px solid #ddd; */
  border-radius: 3px;
  /* background: #fff; */
  background: #f5f5f5;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
  padding: .1em;
  border-radius: .3em;
  white-space: normal;
  background: #f5f5f5;
}

.token.comment,
.token.blockquote {
  color: #969896;
}

.token.cdata {
  color: #183691;
}

.token.doctype,
.token.punctuation,
.token.variable,
.token.macro.property {
  color: #333;
}

.token.operator,
.token.important,
.token.keyword,
.token.rule,
.token.builtin {
  color: #a71d5d;
}

.token.string,
.token.url,
.token.regex,
.token.attr-value {
  color: #183691;
}

.token.property,
.token.number,
.token.boolean,
.token.entity,
.token.atrule,
.token.constant,
.token.symbol,
.token.command,
.token.code {
  color: #0086b3;
}

.token.tag,
.token.selector,
.token.prolog {
  color: #63a35c;
}

.token.function,
.token.namespace,
.token.pseudo-element,
.token.class,
.token.class-name,
.token.pseudo-class,
.token.id,
.token.url-reference .token.variable,
.token.attr-name {
  color: #795da3;
}

.token.entity {
  cursor: help;
}

.token.title,
.token.title .token.punctuation {
  font-weight: bold;
  color: #1d3e81;
}

.token.list {
  color: #ed6a43;
}

.token.inserted {
  background-color: #eaffea;
  color: #55a532;
}

.token.deleted {
  background-color: #ffecec;
  color: #bd2c00;
}

.token.bold {
  font-weight: bold;
}

.token.italic {
  font-style: italic;
}


/* JSON */
.language-json .token.property {
  color: #183691;
}

.language-markup .token.tag .token.punctuation {
  color: #333;
}

/* CSS */
code.language-css,
.language-css .token.function {
  color: #0086b3;
}

/* YAML */
.language-yaml .token.atrule {
  color: #63a35c;
}

code.language-yaml {
  color: #183691;
}

/* Ruby */
.language-ruby .token.function {
  color: #333;
}

/* Markdown */
.language-markdown .token.url {
  color: #795da3;
}

/* Makefile */
.language-makefile .token.symbol {
  color: #795da3;
}

.language-makefile .token.variable {
  color: #183691;
}

.language-makefile .token.builtin {
  color: #0086b3;
}

/* Bash */
.language-bash .token.keyword {
  color: #0086b3;
}

/* highlight */
pre[data-line] {
  position: relative;
  padding: 1em 0 1em 3em;
}
pre[data-line] .line-highlight-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  background-color: transparent;
  display: block;
  width: 100%;
}

pre[data-line] .line-highlight {
  position: absolute;
  left: 0;
  right: 0;
  padding: inherit 0;
  margin-top: 1em;
  background: hsla(24, 20%, 50%,.08);
  background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
  pointer-events: none;
  line-height: inherit;
  white-space: pre;
}

pre[data-line] .line-highlight:before, 
pre[data-line] .line-highlight[data-end]:after {
  content: attr(data-start);
  position: absolute;
  top: .4em;
  left: .6em;
  min-width: 1em;
  padding: 0 .5em;
  background-color: hsla(24, 20%, 50%,.4);
  color: hsl(24, 20%, 95%);
  font: bold 65%/1.5 sans-serif;
  text-align: center;
  vertical-align: .3em;
  border-radius: 999px;
  text-shadow: none;
  box-shadow: 0 1px white;
}

pre[data-line] .line-highlight[data-end]:after {
  content: attr(data-end);
  top: auto;
  bottom: .4em;
}html body{font-family:"Helvetica Neue",Helvetica,"Segoe UI",Arial,freesans,sans-serif;font-size:16px;line-height:1.6;color:#333;background-color:#fff;overflow:initial;box-sizing:border-box;word-wrap:break-word}html body>:first-child{margin-top:0}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{line-height:1.2;margin-top:1em;margin-bottom:16px;color:#000}html body h1{font-size:2.25em;font-weight:300;padding-bottom:.3em}html body h2{font-size:1.75em;font-weight:400;padding-bottom:.3em}html body h3{font-size:1.5em;font-weight:500}html body h4{font-size:1.25em;font-weight:600}html body h5{font-size:1.1em;font-weight:600}html body h6{font-size:1em;font-weight:600}html body h1,html body h2,html body h3,html body h4,html body h5{font-weight:600}html body h5{font-size:1em}html body h6{color:#5c5c5c}html body strong{color:#000}html body del{color:#5c5c5c}html body a:not([href]){color:inherit;text-decoration:none}html body a{color:#08c;text-decoration:none}html body a:hover{color:#00a3f5;text-decoration:none}html body img{max-width:100%}html body>p{margin-top:0;margin-bottom:16px;word-wrap:break-word}html body>ul,html body>ol{margin-bottom:16px}html body ul,html body ol{padding-left:2em}html body ul.no-list,html body ol.no-list{padding:0;list-style-type:none}html body ul ul,html body ul ol,html body ol ol,html body ol ul{margin-top:0;margin-bottom:0}html body li{margin-bottom:0}html body li.task-list-item{list-style:none}html body li>p{margin-top:0;margin-bottom:0}html body .task-list-item-checkbox{margin:0 .2em .25em -1.8em;vertical-align:middle}html body .task-list-item-checkbox:hover{cursor:pointer}html body blockquote{margin:16px 0;font-size:inherit;padding:0 15px;color:#5c5c5c;background-color:#f0f0f0;border-left:4px solid #d6d6d6}html body blockquote>:first-child{margin-top:0}html body blockquote>:last-child{margin-bottom:0}html body hr{height:4px;margin:32px 0;background-color:#d6d6d6;border:0 none}html body table{margin:10px 0 15px 0;border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}html body table th{font-weight:bold;color:#000}html body table td,html body table th{border:1px solid #d6d6d6;padding:6px 13px}html body dl{padding:0}html body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:bold}html body dl dd{padding:0 16px;margin-bottom:16px}html body code{font-family:Menlo,Monaco,Consolas,'Courier New',monospace;font-size:.85em !important;color:#000;background-color:#f0f0f0;border-radius:3px;padding:.2em 0}html body code::before,html body code::after{letter-spacing:-0.2em;content:"\00a0"}html body pre>code{padding:0;margin:0;font-size:.85em !important;word-break:normal;white-space:pre;background:transparent;border:0}html body .highlight{margin-bottom:16px}html body .highlight pre,html body pre{padding:1em;overflow:auto;font-size:.85em !important;line-height:1.45;border:#d6d6d6;border-radius:3px}html body .highlight pre{margin-bottom:0;word-break:normal}html body pre code,html body pre tt{display:inline;max-width:initial;padding:0;margin:0;overflow:initial;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}html body pre code:before,html body pre tt:before,html body pre code:after,html body pre tt:after{content:normal}html body p,html body blockquote,html body ul,html body ol,html body dl,html body pre{margin-top:0;margin-bottom:16px}html body kbd{color:#000;border:1px solid #d6d6d6;border-bottom:2px solid #c7c7c7;padding:2px 4px;background-color:#f0f0f0;border-radius:3px}@media print{html body{background-color:#fff}html body h1,html body h2,html body h3,html body h4,html body h5,html body h6{color:#000;page-break-after:avoid}html body blockquote{color:#5c5c5c}html body pre{page-break-inside:avoid}html body table{display:table}html body img{display:block;max-width:100%;max-height:100%}html body pre,html body code{word-wrap:break-word;white-space:pre}}.markdown-preview{width:100%;height:100%;box-sizing:border-box}.markdown-preview .pagebreak,.markdown-preview .newpage{page-break-before:always}.markdown-preview pre.line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}.markdown-preview pre.line-numbers>code{position:relative}.markdown-preview pre.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:1em;font-size:100%;left:0;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.markdown-preview pre.line-numbers .line-numbers-rows>span{pointer-events:none;display:block;counter-increment:linenumber}.markdown-preview pre.line-numbers .line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right}.markdown-preview .mathjax-exps .MathJax_Display{text-align:center !important}.markdown-preview:not([for="preview"]) .code-chunk .btn-group{display:none}.markdown-preview:not([for="preview"]) .code-chunk .status{display:none}.markdown-preview:not([for="preview"]) .code-chunk .output-div{margin-bottom:16px}.markdown-preview .md-toc{padding:0}.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link{display:inline;padding:.25rem 0}.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link p,.markdown-preview .md-toc .md-toc-link-wrapper .md-toc-link div{display:inline}.markdown-preview .md-toc .md-toc-link-wrapper.highlighted .md-toc-link{font-weight:800}.scrollbar-style::-webkit-scrollbar{width:8px}.scrollbar-style::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}.scrollbar-style::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode]){position:relative;width:100%;height:100%;top:0;left:0;margin:0;padding:0;overflow:auto}html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{position:relative;top:0}@media screen and (min-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em calc(50% - 457px + 2em)}}@media screen and (max-width:914px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode]) .markdown-preview{font-size:14px !important;padding:1em}}@media print{html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{display:none}}html body[for="html-export"]:not([data-presentation-mode]) #sidebar-toc-btn{position:fixed;bottom:8px;left:8px;font-size:28px;cursor:pointer;color:inherit;z-index:99;width:32px;text-align:center;opacity:.4}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] #sidebar-toc-btn{opacity:1}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc{position:fixed;top:0;left:0;width:300px;height:100%;padding:32px 0 48px 0;font-size:14px;box-shadow:0 0 4px rgba(150,150,150,0.33);box-sizing:border-box;overflow:auto;background-color:inherit}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar{width:8px}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-track{border-radius:10px;background-color:transparent}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc::-webkit-scrollbar-thumb{border-radius:5px;background-color:rgba(150,150,150,0.66);border:4px solid rgba(150,150,150,0.66);background-clip:content-box}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc a{text-decoration:none}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc{padding:0 16px}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link{display:inline;padding:.25rem 0}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link p,html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper .md-toc-link div{display:inline}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .md-sidebar-toc .md-toc .md-toc-link-wrapper.highlighted .md-toc-link{font-weight:800}html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{left:300px;width:calc(100% -  300px);padding:2em calc(50% - 457px -  300px/2);margin:0;box-sizing:border-box}@media screen and (max-width:1274px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{padding:2em}}@media screen and (max-width:450px){html body[for="html-export"]:not([data-presentation-mode])[html-show-sidebar-toc] .markdown-preview{width:100%}}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .markdown-preview{left:50%;transform:translateX(-50%)}html body[for="html-export"]:not([data-presentation-mode]):not([html-show-sidebar-toc]) .md-sidebar-toc{display:none}
/* Please visit the URL below for more information: */
/*   https://shd101wyy.github.io/markdown-preview-enhanced/#/customize-css */

      </style>
    </head>
    <body for="html-export">
      <div class="mume markdown-preview  ">
      <center>
<h1>YOLO-Face &#x8BAD;&#x7EC3;&#x548C;&#x8C03;&#x7528;&#x6307;&#x5357;</h1>
</center>
<h2 class="mume-header" id="1-%E4%B8%8B%E8%BD%BD%E6%BA%90%E7%A0%81">1. &#x4E0B;&#x8F7D;&#x6E90;&#x7801;</h2>

<p>&#x7F51;&#x5740;&#xFF1A;<a href="https://github.com/deepcam-cn/yolov5-face">https://github.com/deepcam-cn/yolov5-face</a></p>
<h2 class="mume-header" id="2-%E5%87%86%E5%A4%87%E6%95%B0%E6%8D%AE%E9%9B%86">2. &#x51C6;&#x5907;&#x6570;&#x636E;&#x96C6;</h2>

<p>yoloface &#x7684;&#x6807;&#x7B7E;&#x4F9D;&#x7136;&#x7528; txt &#x4FDD;&#x5B58;&#xFF0C;&#x524D; 5 &#x4E2A;&#x53C2;&#x6570;&#x4E0E;&#x4E00;&#x822C;&#x7684; yolo &#x76F8;&#x540C;&#xFF08;&#x6807;&#x7B7E;id, x, y, w, h&#xFF09;&#xFF0C;&#x5728;&#x6B64;&#x57FA;&#x7840;&#x4E0A;&#x52A0;&#x4E86; 10 &#x4E2A;&#x53C2;&#x6570;&#xFF0C;&#x5206;&#x522B;&#x4E3A; &#xFF08;x1, y1, x2, y2, x3, y3, x4, y4, x5, y5&#xFF09;&#xFF0C;&#x5373;&#x8868;&#x793A;&#x4E94;&#x4E2A;&#x70B9;&#x7684;&#x5750;&#x6807;&#x3002;</p>
<p>&#x53EF;&#x81EA;&#x884C;&#x4F7F;&#x7528;&#x811A;&#x672C;&#x8FDB;&#x884C;&#x8F6C;&#x5316;&#xFF0C;&#x6216;&#x8005;&#x4F7F;&#x7528; yoloface &#x4E2D;&#x81EA;&#x5E26;&#x7684;&#x8F6C;&#x5316;&#x5DE5;&#x5177;</p>
<h2 class="mume-header" id="3-%E5%B0%86%E6%95%B0%E6%8D%AE%E6%8C%89%E7%85%A7%E6%8C%87%E5%AE%9A%E6%A0%BC%E5%BC%8F%E4%BF%9D%E5%AD%98%E5%BC%80%E5%A7%8B%E8%AE%AD%E7%BB%83">3. &#x5C06;&#x6570;&#x636E;&#x6309;&#x7167;&#x6307;&#x5B9A;&#x683C;&#x5F0F;&#x4FDD;&#x5B58;&#xFF0C;&#x5F00;&#x59CB;&#x8BAD;&#x7EC3;</h2>

<p>&#x53EF;&#x53C2;&#x8003;&#x535A;&#x5BA2; <a href="https://blog.csdn.net/qq_51303289/article/details/127299175">https://blog.csdn.net/qq_51303289/article/details/127299175</a></p>
<p>&#x867D;&#x7136;&#x662F;&#x4E00;&#x822C;&#x7684; yolo&#xFF0C;&#x4F46;&#x662F;&#x64CD;&#x4F5C;&#x662F;&#x4E00;&#x6837;&#x7684;&#x3002;</p>
<h2 class="mume-header" id="4-%E8%B0%83%E7%94%A8">4. &#x8C03;&#x7528;</h2>

<p>&#x5C06;&#x8BAD;&#x7EC3;&#x597D;&#x7684;&#x6A21;&#x578B;&#x8F6C;&#x5316;&#x4E3A; onnx&#xFF0C;&#x4E4B;&#x540E;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x901A;&#x8FC7; OpenCV &#x6765;&#x8FDB;&#x884C;&#x8C03;&#x7528;&#xFF08;&#x9700;&#x8981;&#x642D;&#x914D; contrib &#x4E00;&#x8D77;&#xFF09;&#x3002;</p>
<p>&#x6E90;&#x7801;&#x5982;&#x4E0B;&#xFF0C;&#x53EF;&#x76F4;&#x63A5;&#x590D;&#x5236;&#x7F16;&#x8BD1;&#x4F7F;&#x7528;&#xFF1A;</p>
<p>detector.hpp &#x5934;&#x6587;&#x4EF6;</p>
<pre data-role="codeBlock" data-info="cpp" class="language-cpp"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">ifndef</span> <span class="token expression">DETECTOR__DETECTOR_HPP</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">define</span> <span class="token macro-name">DETECTOR__DETECTOR_HPP</span></span>

<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;opencv2/opencv.hpp&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;opencv2/dnn.hpp&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;opencv2/imgproc.hpp&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;opencv2/highgui.hpp&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;ros/ros.h&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;string&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;vector&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;fstream&gt;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;stdio.h&gt;</span></span>


<span class="token keyword keyword-namespace">namespace</span> rune_detector<span class="token punctuation">{</span>


<span class="token keyword keyword-struct">struct</span> <span class="token class-name">detectParam</span><span class="token punctuation">{</span>
	<span class="token keyword keyword-bool">bool</span> debug<span class="token punctuation">;</span>
	<span class="token keyword keyword-float">float</span> input_width<span class="token punctuation">;</span>
	<span class="token keyword keyword-float">float</span> input_height<span class="token punctuation">;</span>
	<span class="token keyword keyword-float">float</span> score_threshold<span class="token punctuation">;</span>
	<span class="token keyword keyword-float">float</span> nms_threshold<span class="token punctuation">;</span>
	<span class="token keyword keyword-float">float</span> conf_threshold<span class="token punctuation">;</span>
	<span class="token keyword keyword-int">int</span> device<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword keyword-struct">struct</span> <span class="token class-name">Detection</span><span class="token punctuation">{</span>
	<span class="token keyword keyword-int">int</span> class_id<span class="token punctuation">;</span>
	<span class="token keyword keyword-float">float</span> confidence<span class="token punctuation">;</span>
	cv<span class="token double-colon punctuation">::</span>Rect box<span class="token punctuation">;</span>
    std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>Point<span class="token operator">&gt;</span> points<span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>

<span class="token keyword keyword-class">class</span> <span class="token class-name">Detector</span>
<span class="token punctuation">{</span>
<span class="token keyword keyword-public">public</span><span class="token operator">:</span>
<span class="token keyword keyword-using">using</span> Ptr <span class="token operator">=</span> std<span class="token double-colon punctuation">::</span>unique_ptr<span class="token operator">&lt;</span>Detector<span class="token operator">&gt;</span><span class="token punctuation">;</span>

	<span class="token function">Detector</span><span class="token punctuation">(</span><span class="token keyword keyword-const">const</span> detectParam <span class="token operator">&amp;</span>param<span class="token punctuation">,</span> <span class="token keyword keyword-const">const</span> cv<span class="token double-colon punctuation">::</span>String <span class="token operator">&amp;</span>model_path<span class="token punctuation">,</span> <span class="token keyword keyword-const">const</span> std<span class="token double-colon punctuation">::</span>string <span class="token operator">&amp;</span>class_path<span class="token punctuation">)</span><span class="token punctuation">;</span>
	
	<span class="token keyword keyword-bool">bool</span> <span class="token function">getTarget</span><span class="token punctuation">(</span><span class="token keyword keyword-const">const</span> cv<span class="token double-colon punctuation">::</span>Mat <span class="token operator">&amp;</span>image<span class="token punctuation">,</span>std<span class="token double-colon punctuation">::</span>array<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>Point<span class="token punctuation">,</span><span class="token number">5</span><span class="token operator">&gt;</span> <span class="token operator">&amp;</span>pts<span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//return false if no target found</span>
<span class="token keyword keyword-private">private</span><span class="token operator">:</span>
	detectParam param_<span class="token punctuation">;</span>
	std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>std<span class="token double-colon punctuation">::</span>string<span class="token operator">&gt;</span> class_list_<span class="token punctuation">;</span>
	<span class="token keyword keyword-void">void</span> <span class="token function">detect_face</span><span class="token punctuation">(</span><span class="token keyword keyword-const">const</span> cv<span class="token double-colon punctuation">::</span>Mat <span class="token operator">&amp;</span>image<span class="token punctuation">,</span> std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>Detection<span class="token operator">&gt;</span><span class="token operator">&amp;</span> outputs<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token keyword keyword-void">void</span> <span class="token function">detect_yolox</span><span class="token punctuation">(</span><span class="token keyword keyword-const">const</span> cv<span class="token double-colon punctuation">::</span>Mat <span class="token operator">&amp;</span>image<span class="token punctuation">,</span> std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>Detection<span class="token operator">&gt;</span><span class="token operator">&amp;</span> outputs<span class="token punctuation">)</span><span class="token punctuation">;</span>

	ros<span class="token double-colon punctuation">::</span>Publisher debug_img_pub_<span class="token punctuation">;</span>
	
	<span class="token keyword keyword-bool">bool</span> <span class="token function">detect_hit_error</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//to futher design</span>

	cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span>Net net_<span class="token punctuation">;</span>
	cv<span class="token double-colon punctuation">::</span>Mat debug_img_<span class="token punctuation">;</span>

<span class="token keyword keyword-private">private</span><span class="token operator">:</span>

	<span class="token keyword keyword-void">void</span> <span class="token function">Dump</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">;</span>


<span class="token keyword keyword-const">const</span> std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>Scalar<span class="token operator">&gt;</span> colors <span class="token operator">=</span> <span class="token punctuation">{</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Scalar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Scalar</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Scalar</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Scalar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>	<span class="token comment">//namespace detector</span>




<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">endif</span></span>
</pre><p>detector.cpp &#x6E90;&#x6587;&#x4EF6;</p>
<pre data-role="codeBlock" data-info="cpp" class="language-cpp"><span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&quot;rune_detector/detector.hpp&quot;</span></span>
<span class="token macro property"><span class="token directive-hash">#</span><span class="token directive keyword">include</span> <span class="token string">&lt;sensor_msgs/Image.h&gt;</span></span>

<span class="token keyword keyword-namespace">namespace</span> rune_detector<span class="token punctuation">{</span>

<span class="token class-name">Detector</span><span class="token double-colon punctuation">::</span><span class="token function">Detector</span><span class="token punctuation">(</span><span class="token keyword keyword-const">const</span> detectParam <span class="token operator">&amp;</span>param<span class="token punctuation">,</span> <span class="token keyword keyword-const">const</span> cv<span class="token double-colon punctuation">::</span>String <span class="token operator">&amp;</span>model_path<span class="token punctuation">,</span> <span class="token keyword keyword-const">const</span> std<span class="token double-colon punctuation">::</span>string <span class="token operator">&amp;</span>class_path<span class="token punctuation">)</span>
<span class="token operator">:</span><span class="token function">param_</span><span class="token punctuation">(</span>param<span class="token punctuation">)</span>
<span class="token punctuation">{</span>
	<span class="token comment">//&#x52A0;&#x8F7D;&#x6A21;&#x578B;</span>
	<span class="token keyword keyword-auto">auto</span> result <span class="token operator">=</span> cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span><span class="token function">readNetFromONNX</span><span class="token punctuation">(</span>model_path<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//readNet   &#x4EE3;&#x7801;&#x53EF;&#x7528; &#x7248;&#x672C;&#x6709;&#x95EE;&#x9898;</span>
	<span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>param_<span class="token punctuation">.</span>device<span class="token operator">==</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token comment">//NX</span>
	<span class="token punctuation">{</span>
		std<span class="token double-colon punctuation">::</span>cout <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;Attempty to use CUDA\n&quot;</span><span class="token punctuation">;</span>
		result<span class="token punctuation">.</span><span class="token function">setPreferableTarget</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span>DNN_TARGET_CUDA<span class="token punctuation">)</span><span class="token punctuation">;</span>
		result<span class="token punctuation">.</span><span class="token function">setPreferableBackend</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span>DNN_BACKEND_CUDA<span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token comment">//result.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA_FP16);</span>
	<span class="token punctuation">}</span>
	<span class="token keyword keyword-else">else</span> <span class="token keyword keyword-if">if</span><span class="token punctuation">(</span>param_<span class="token punctuation">.</span>device<span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">)</span> <span class="token comment">//NUC</span>
	<span class="token punctuation">{</span>
		std<span class="token double-colon punctuation">::</span>cout <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;Running on OpenVINO\n&quot;</span><span class="token punctuation">;</span>
		result<span class="token punctuation">.</span><span class="token function">setPreferableBackend</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span>DNN_BACKEND_INFERENCE_ENGINE<span class="token punctuation">)</span><span class="token punctuation">;</span>
		result<span class="token punctuation">.</span><span class="token function">setPreferableTarget</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span>DNN_TARGET_OPENCL<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token keyword keyword-else">else</span><span class="token punctuation">{</span>
		std<span class="token double-colon punctuation">::</span>cout <span class="token operator">&lt;&lt;</span> <span class="token string">&quot;Running on CPU\n&quot;</span><span class="token punctuation">;</span>
		result<span class="token punctuation">.</span><span class="token function">setPreferableBackend</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span>DNN_BACKEND_OPENCV<span class="token punctuation">)</span><span class="token punctuation">;</span>
		result<span class="token punctuation">.</span><span class="token function">setPreferableTarget</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span>DNN_TARGET_CPU<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	net_ <span class="token operator">=</span> result<span class="token punctuation">;</span>

	<span class="token comment">//&#x52A0;&#x8F7D;&#x7C7B;&#x5206;&#x7C7B;&#x5668;</span>
	std<span class="token double-colon punctuation">::</span>ifstream <span class="token function">ifs</span><span class="token punctuation">(</span>class_path<span class="token punctuation">)</span><span class="token punctuation">;</span>
	std<span class="token double-colon punctuation">::</span>string line<span class="token punctuation">;</span>
	<span class="token keyword keyword-while">while</span> <span class="token punctuation">(</span><span class="token function">getline</span><span class="token punctuation">(</span>ifs<span class="token punctuation">,</span> line<span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token punctuation">{</span>
		class_list_<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>line<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token comment">// debug_img_pub_ = nh_.advertise&lt;sensor_msgs::Image&gt;(&quot;/rune_detect_result&quot;,1);</span>

<span class="token punctuation">}</span>

<span class="token keyword keyword-bool">bool</span> <span class="token class-name">Detector</span><span class="token double-colon punctuation">::</span><span class="token function">getTarget</span><span class="token punctuation">(</span><span class="token keyword keyword-const">const</span> cv<span class="token double-colon punctuation">::</span>Mat <span class="token operator">&amp;</span>image<span class="token punctuation">,</span>std<span class="token double-colon punctuation">::</span>array<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>Point<span class="token punctuation">,</span><span class="token number">5</span><span class="token operator">&gt;</span> <span class="token operator">&amp;</span>pts<span class="token punctuation">)</span><span class="token punctuation">{</span>
	
	<span class="token keyword keyword-if">if</span><span class="token punctuation">(</span>param_<span class="token punctuation">.</span>debug<span class="token punctuation">)</span><span class="token punctuation">{</span>
		debug_img_ <span class="token operator">=</span> image<span class="token punctuation">.</span><span class="token function">clone</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
	<span class="token comment">//&#x5F97;&#x5230; output &#x7ED3;&#x679C;</span>
	std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>Detection<span class="token operator">&gt;</span> output<span class="token punctuation">;</span>
	<span class="token function">detect_face</span><span class="token punctuation">(</span>image<span class="token punctuation">,</span>output<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token comment">// detect_yolox(image,output);</span>
	<span class="token keyword keyword-if">if</span><span class="token punctuation">(</span>output<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">==</span><span class="token number">0</span><span class="token punctuation">)</span>
		<span class="token keyword keyword-return">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>

	<span class="token comment">//&#x5BFB;&#x627E;&#x5F85;&#x51FB;&#x6253;&#x6247;&#x53F6;&#x548C; R &#x6807;</span>
	<span class="token keyword keyword-bool">bool</span> find_r<span class="token operator">=</span><span class="token boolean">false</span><span class="token punctuation">,</span> find_hit <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
	Detection r<span class="token punctuation">,</span>hit<span class="token punctuation">;</span>

	<span class="token keyword keyword-for">for</span><span class="token punctuation">(</span><span class="token keyword keyword-auto">auto</span> result<span class="token operator">:</span>output<span class="token punctuation">)</span><span class="token punctuation">{</span>
		<span class="token keyword keyword-if">if</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span>class_id<span class="token operator">==</span><span class="token number">0</span> <span class="token operator">||</span> result<span class="token punctuation">.</span>class_id<span class="token operator">==</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
			r <span class="token operator">=</span> result<span class="token punctuation">;</span>
			find_r <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		<span class="token keyword keyword-else">else</span> <span class="token keyword keyword-if">if</span><span class="token punctuation">(</span>result<span class="token punctuation">.</span>class_id<span class="token operator">==</span><span class="token number">1</span> <span class="token operator">||</span> result<span class="token punctuation">.</span>class_id<span class="token operator">==</span><span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
			hit <span class="token operator">=</span> result<span class="token punctuation">;</span>
			find_hit <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
		<span class="token punctuation">}</span>
		
		<span class="token keyword keyword-if">if</span><span class="token punctuation">(</span>find_r<span class="token operator">&amp;&amp;</span>find_hit<span class="token punctuation">)</span> <span class="token keyword keyword-break">break</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>

	<span class="token keyword keyword-if">if</span><span class="token punctuation">(</span><span class="token operator">!</span>find_r <span class="token operator">||</span> <span class="token operator">!</span>find_hit<span class="token punctuation">)</span>
		<span class="token keyword keyword-return">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>

	<span class="token comment">//&#x5224;&#x65AD;&#x662F;&#x5426;&#x51FA;&#x73B0;&#x68C0;&#x6D4B;&#x9519;&#x8BEF;&#x7684;&#x60C5;&#x51B5; TODO</span>
	<span class="token comment">// if(!detect_hit_error()) return false;</span>


	<span class="token comment">//&#x5C06;5&#x70B9;&#x8D4B;&#x503C;&#x7ED9; pts</span>
	
	pts<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span> <span class="token operator">=</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Point</span><span class="token punctuation">(</span>r<span class="token punctuation">.</span>box<span class="token punctuation">.</span>x<span class="token operator">+</span><span class="token number">0.5</span><span class="token operator">*</span>r<span class="token punctuation">.</span>box<span class="token punctuation">.</span>width<span class="token punctuation">,</span>r<span class="token punctuation">.</span>box<span class="token punctuation">.</span>y<span class="token operator">+</span><span class="token number">0.5</span><span class="token operator">*</span>r<span class="token punctuation">.</span>box<span class="token punctuation">.</span>height<span class="token punctuation">)</span><span class="token punctuation">;</span>
	pts<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> hit<span class="token punctuation">.</span>points<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
	pts<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span> <span class="token operator">=</span> hit<span class="token punctuation">.</span>points<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
	pts<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span> <span class="token operator">=</span> hit<span class="token punctuation">.</span>points<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
	pts<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span> <span class="token operator">=</span> hit<span class="token punctuation">.</span>points<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>



	<span class="token keyword keyword-return">return</span> <span class="token boolean">true</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword keyword-void">void</span> <span class="token class-name">Detector</span><span class="token double-colon punctuation">::</span><span class="token function">detect_face</span><span class="token punctuation">(</span><span class="token keyword keyword-const">const</span> cv<span class="token double-colon punctuation">::</span>Mat <span class="token operator">&amp;</span>image<span class="token punctuation">,</span> std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>Detection<span class="token operator">&gt;</span><span class="token operator">&amp;</span> output<span class="token punctuation">)</span><span class="token punctuation">{</span>

	cv<span class="token double-colon punctuation">::</span>Mat blob<span class="token punctuation">;</span>
	<span class="token keyword keyword-auto">auto</span> input_image <span class="token operator">=</span> image<span class="token punctuation">.</span><span class="token function">clone</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
 
	cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span><span class="token function">blobFromImage</span><span class="token punctuation">(</span>input_image<span class="token punctuation">,</span> blob<span class="token punctuation">,</span> <span class="token number">1.</span> <span class="token operator">/</span> <span class="token number">255.</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Size</span><span class="token punctuation">(</span>param_<span class="token punctuation">.</span>input_width<span class="token punctuation">,</span> param_<span class="token punctuation">.</span>input_height<span class="token punctuation">)</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Scalar</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	net_<span class="token punctuation">.</span><span class="token function">setInput</span><span class="token punctuation">(</span>blob<span class="token punctuation">)</span><span class="token punctuation">;</span>
	std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>Mat<span class="token operator">&gt;</span> outputs<span class="token punctuation">;</span>
	std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>String<span class="token operator">&gt;</span> blobnames <span class="token operator">=</span> net_<span class="token punctuation">.</span><span class="token function">getUnconnectedOutLayersNames</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token comment">// std::cout &lt;&lt; &quot;before forward\n&quot;;</span>
	net_<span class="token punctuation">.</span><span class="token function">forward</span><span class="token punctuation">(</span>outputs<span class="token punctuation">,</span> blobnames<span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment">//da4dnn::checkVersions CUDART version 11030 reported by cuDNN 8200 does not match with the version reported by CUDART 11010</span>
    
    <span class="token comment">// std::cout&lt;&lt;outputs[0].size[0]&lt;&lt;&quot;x&quot;&lt;&lt;outputs[0].size[1]&lt;&lt;&quot;x&quot;&lt;&lt;outputs[0].size[2]&lt;&lt;std::endl;</span>
 
	<span class="token comment">//outputs = net.forward();</span>
	<span class="token comment">// std::cout &lt;&lt; &quot;after forward\n&quot;;</span>
	<span class="token keyword keyword-float">float</span> x_factor <span class="token operator">=</span> input_image<span class="token punctuation">.</span>cols <span class="token operator">/</span> param_<span class="token punctuation">.</span>input_width<span class="token punctuation">;</span>
	<span class="token keyword keyword-float">float</span> y_factor <span class="token operator">=</span> input_image<span class="token punctuation">.</span>rows <span class="token operator">/</span> param_<span class="token punctuation">.</span>input_height<span class="token punctuation">;</span>
 
	<span class="token keyword keyword-float">float</span><span class="token operator">*</span> data <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword keyword-float">float</span><span class="token operator">*</span><span class="token punctuation">)</span>outputs<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>data<span class="token punctuation">;</span>
 
	<span class="token keyword keyword-int">int</span> dimensions <span class="token operator">=</span> outputs<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>size<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
	<span class="token keyword keyword-int">int</span> rows <span class="token operator">=</span> outputs<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>size<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token comment">//25200</span>
 
	std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span><span class="token keyword keyword-int">int</span><span class="token operator">&gt;</span> class_ids<span class="token punctuation">;</span>
	std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span><span class="token keyword keyword-float">float</span><span class="token operator">&gt;</span> confidences<span class="token punctuation">;</span>
	std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>Rect<span class="token operator">&gt;</span> boxes<span class="token punctuation">;</span>
    std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>Point<span class="token operator">&gt;&gt;</span> points<span class="token punctuation">;</span>

	<span class="token comment">// Yolo-face</span>
	<span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> rows<span class="token punctuation">;</span> <span class="token operator">++</span>i<span class="token punctuation">)</span> <span class="token punctuation">{</span>
 
		<span class="token keyword keyword-float">float</span> confidence <span class="token operator">=</span> data<span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token punctuation">;</span><span class="token comment">// data[4]</span>
        <span class="token comment">// for(int i=0;i&lt;30;i++){</span>
        <span class="token comment">//     std::cout&lt;&lt;data[i]&lt;&lt;&quot; &quot;;</span>
        <span class="token comment">// }</span>
        <span class="token comment">// std::cout&lt;&lt;std::endl;</span>
        <span class="token comment">// std::cout&lt;&lt;confidence&lt;&lt;std::endl;</span>
		<span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>confidence <span class="token operator">&gt;=</span> param_<span class="token punctuation">.</span>conf_threshold<span class="token punctuation">)</span> <span class="token punctuation">{</span>
 
			<span class="token keyword keyword-float">float</span><span class="token operator">*</span> classes_scores <span class="token operator">=</span> data <span class="token operator">+</span> <span class="token number">15</span><span class="token punctuation">;</span>
			cv<span class="token double-colon punctuation">::</span>Mat <span class="token function">scores</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> class_list_<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> CV_32FC1<span class="token punctuation">,</span> classes_scores<span class="token punctuation">)</span><span class="token punctuation">;</span>
			cv<span class="token double-colon punctuation">::</span>Point class_id<span class="token punctuation">;</span>
			<span class="token keyword keyword-double">double</span> max_class_score<span class="token punctuation">;</span>
			<span class="token function">minMaxLoc</span><span class="token punctuation">(</span>scores<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token operator">&amp;</span>max_class_score<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token operator">&amp;</span>class_id<span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token comment">// std::cout&lt;&lt;max_class_score&lt;&lt;std::endl;</span>
			<span class="token keyword keyword-if">if</span> <span class="token punctuation">(</span>max_class_score <span class="token operator">&gt;</span> param_<span class="token punctuation">.</span>score_threshold<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">// std::cout&lt;&lt;max_class_score&lt;&lt;std::endl;</span>
 
				confidences<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>confidence<span class="token punctuation">)</span><span class="token punctuation">;</span>
 
				class_ids<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>class_id<span class="token punctuation">.</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span>
 
				<span class="token keyword keyword-float">float</span> x <span class="token operator">=</span> data<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
				<span class="token keyword keyword-float">float</span> y <span class="token operator">=</span> data<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
				<span class="token keyword keyword-float">float</span> w <span class="token operator">=</span> data<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
				<span class="token keyword keyword-float">float</span> h <span class="token operator">=</span> data<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
				<span class="token keyword keyword-int">int</span> left <span class="token operator">=</span> <span class="token keyword keyword-int">int</span><span class="token punctuation">(</span><span class="token punctuation">(</span>x <span class="token operator">-</span> <span class="token number">0.5</span> <span class="token operator">*</span> w<span class="token punctuation">)</span> <span class="token operator">*</span> x_factor<span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token keyword keyword-int">int</span> top <span class="token operator">=</span> <span class="token keyword keyword-int">int</span><span class="token punctuation">(</span><span class="token punctuation">(</span>y <span class="token operator">-</span> <span class="token number">0.5</span> <span class="token operator">*</span> h<span class="token punctuation">)</span> <span class="token operator">*</span> y_factor<span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token keyword keyword-int">int</span> width <span class="token operator">=</span> <span class="token keyword keyword-int">int</span><span class="token punctuation">(</span>w <span class="token operator">*</span> x_factor<span class="token punctuation">)</span><span class="token punctuation">;</span>
				<span class="token keyword keyword-int">int</span> height <span class="token operator">=</span> <span class="token keyword keyword-int">int</span><span class="token punctuation">(</span>h <span class="token operator">*</span> y_factor<span class="token punctuation">)</span><span class="token punctuation">;</span>
                std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>Point<span class="token operator">&gt;</span> p<span class="token punctuation">;</span>
                p<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span><span class="token function">Point</span><span class="token punctuation">(</span>data<span class="token punctuation">[</span><span class="token number">5</span><span class="token punctuation">]</span><span class="token operator">*</span>x_factor<span class="token punctuation">,</span>data<span class="token punctuation">[</span><span class="token number">6</span><span class="token punctuation">]</span><span class="token operator">*</span>y_factor<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                p<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span><span class="token function">Point</span><span class="token punctuation">(</span>data<span class="token punctuation">[</span><span class="token number">7</span><span class="token punctuation">]</span><span class="token operator">*</span>x_factor<span class="token punctuation">,</span>data<span class="token punctuation">[</span><span class="token number">8</span><span class="token punctuation">]</span><span class="token operator">*</span>y_factor<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                p<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span><span class="token function">Point</span><span class="token punctuation">(</span>data<span class="token punctuation">[</span><span class="token number">9</span><span class="token punctuation">]</span><span class="token operator">*</span>x_factor<span class="token punctuation">,</span>data<span class="token punctuation">[</span><span class="token number">10</span><span class="token punctuation">]</span><span class="token operator">*</span>y_factor<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                p<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span><span class="token function">Point</span><span class="token punctuation">(</span>data<span class="token punctuation">[</span><span class="token number">11</span><span class="token punctuation">]</span><span class="token operator">*</span>x_factor<span class="token punctuation">,</span>data<span class="token punctuation">[</span><span class="token number">12</span><span class="token punctuation">]</span><span class="token operator">*</span>y_factor<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                p<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span><span class="token function">Point</span><span class="token punctuation">(</span>data<span class="token punctuation">[</span><span class="token number">13</span><span class="token punctuation">]</span><span class="token operator">*</span>x_factor<span class="token punctuation">,</span>data<span class="token punctuation">[</span><span class="token number">14</span><span class="token punctuation">]</span><span class="token operator">*</span>y_factor<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

                points<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>p<span class="token punctuation">)</span><span class="token punctuation">;</span>
				boxes<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>cv<span class="token double-colon punctuation">::</span><span class="token function">Rect</span><span class="token punctuation">(</span>left<span class="token punctuation">,</span> top<span class="token punctuation">,</span> width<span class="token punctuation">,</span> height<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
 
		<span class="token punctuation">}</span>
 
		data <span class="token operator">+=</span> dimensions<span class="token punctuation">;</span>
 
	<span class="token punctuation">}</span>
	std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span><span class="token keyword keyword-int">int</span><span class="token operator">&gt;</span> nms_result<span class="token punctuation">;</span>
	cv<span class="token double-colon punctuation">::</span>dnn<span class="token double-colon punctuation">::</span><span class="token function">NMSBoxes</span><span class="token punctuation">(</span>boxes<span class="token punctuation">,</span> confidences<span class="token punctuation">,</span> param_<span class="token punctuation">.</span>score_threshold<span class="token punctuation">,</span> param_<span class="token punctuation">.</span>nms_threshold<span class="token punctuation">,</span> nms_result<span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> nms_result<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword keyword-int">int</span> idx <span class="token operator">=</span> nms_result<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
		Detection result<span class="token punctuation">;</span>
		result<span class="token punctuation">.</span>class_id <span class="token operator">=</span> class_ids<span class="token punctuation">[</span>idx<span class="token punctuation">]</span><span class="token punctuation">;</span>
		result<span class="token punctuation">.</span>confidence <span class="token operator">=</span> confidences<span class="token punctuation">[</span>idx<span class="token punctuation">]</span><span class="token punctuation">;</span>
		result<span class="token punctuation">.</span>box <span class="token operator">=</span> boxes<span class="token punctuation">[</span>idx<span class="token punctuation">]</span><span class="token punctuation">;</span>
        result<span class="token punctuation">.</span>points <span class="token operator">=</span> points<span class="token punctuation">[</span>idx<span class="token punctuation">]</span><span class="token punctuation">;</span>
		output<span class="token punctuation">.</span><span class="token function">push_back</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token comment">// pts.push_back(points[idx]);</span>
	<span class="token punctuation">}</span>

	<span class="token keyword keyword-if">if</span><span class="token punctuation">(</span>param_<span class="token punctuation">.</span>debug<span class="token punctuation">)</span><span class="token punctuation">{</span>
		<span class="token keyword keyword-for">for</span> <span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> output<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token operator">++</span>i<span class="token punctuation">)</span>
		<span class="token punctuation">{</span>
			<span class="token keyword keyword-auto">auto</span> detection <span class="token operator">=</span> output<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
			<span class="token keyword keyword-auto">auto</span> box <span class="token operator">=</span> detection<span class="token punctuation">.</span>box<span class="token punctuation">;</span>
			<span class="token keyword keyword-auto">auto</span> classId <span class="token operator">=</span> detection<span class="token punctuation">.</span>class_id<span class="token punctuation">;</span>
			<span class="token keyword keyword-const">const</span> <span class="token keyword keyword-auto">auto</span> color <span class="token operator">=</span> colors<span class="token punctuation">[</span>classId <span class="token operator">%</span> colors<span class="token punctuation">.</span><span class="token function">size</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">]</span><span class="token punctuation">;</span>
			cv<span class="token double-colon punctuation">::</span><span class="token function">putText</span><span class="token punctuation">(</span>debug_img_<span class="token punctuation">,</span> class_list_<span class="token punctuation">[</span>classId<span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">c_str</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Point</span><span class="token punctuation">(</span>box<span class="token punctuation">.</span>x<span class="token punctuation">,</span> box<span class="token punctuation">.</span>y <span class="token operator">-</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span>FONT_HERSHEY_SIMPLEX<span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Scalar</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
			cv<span class="token double-colon punctuation">::</span><span class="token function">putText</span><span class="token punctuation">(</span>debug_img_<span class="token punctuation">,</span> std<span class="token double-colon punctuation">::</span><span class="token function">to_string</span><span class="token punctuation">(</span>detection<span class="token punctuation">.</span>confidence<span class="token punctuation">)</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Point</span><span class="token punctuation">(</span>box<span class="token punctuation">.</span>x<span class="token operator">+</span>box<span class="token punctuation">.</span>width<span class="token operator">*</span><span class="token number">0.5</span><span class="token punctuation">,</span> box<span class="token punctuation">.</span>y <span class="token operator">-</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span>FONT_HERSHEY_SIMPLEX<span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Scalar</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token keyword keyword-for">for</span><span class="token punctuation">(</span><span class="token keyword keyword-int">int</span> j<span class="token operator">=</span><span class="token number">0</span><span class="token punctuation">;</span>j<span class="token operator">&lt;</span><span class="token number">5</span><span class="token punctuation">;</span>j<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
			    cv<span class="token double-colon punctuation">::</span><span class="token function">putText</span><span class="token punctuation">(</span>debug_img_<span class="token punctuation">,</span> std<span class="token double-colon punctuation">::</span><span class="token function">to_string</span><span class="token punctuation">(</span>j<span class="token punctuation">)</span><span class="token punctuation">,</span> detection<span class="token punctuation">.</span>points<span class="token punctuation">[</span>j<span class="token punctuation">]</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span>FONT_HERSHEY_SIMPLEX<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Scalar</span><span class="token punctuation">(</span><span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>

        <span class="token punctuation">}</span>
		<span class="token keyword keyword-static">static</span> <span class="token keyword keyword-double">double</span> last_time <span class="token operator">=</span> ros<span class="token double-colon punctuation">::</span><span class="token class-name">Time</span><span class="token double-colon punctuation">::</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toSec</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		<span class="token keyword keyword-double">double</span> this_time <span class="token operator">=</span> ros<span class="token double-colon punctuation">::</span><span class="token class-name">Time</span><span class="token double-colon punctuation">::</span><span class="token function">now</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">toSec</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		cv<span class="token double-colon punctuation">::</span><span class="token function">putText</span><span class="token punctuation">(</span>debug_img_<span class="token punctuation">,</span> <span class="token string">&quot;delay: &quot;</span><span class="token operator">+</span>std<span class="token double-colon punctuation">::</span><span class="token function">to_string</span><span class="token punctuation">(</span><span class="token punctuation">(</span>this_time<span class="token operator">-</span>last_time<span class="token punctuation">)</span><span class="token operator">*</span><span class="token number">1000</span><span class="token punctuation">)</span><span class="token operator">+</span><span class="token string">&quot; ms&quot;</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Point</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span>FONT_HERSHEY_DUPLEX<span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> cv<span class="token double-colon punctuation">::</span><span class="token function">Scalar</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span> <span class="token number">255</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
		last_time <span class="token operator">=</span> this_time<span class="token punctuation">;</span>
		cv<span class="token double-colon punctuation">::</span><span class="token function">imshow</span><span class="token punctuation">(</span><span class="token string">&quot;result&quot;</span><span class="token punctuation">,</span>debug_img_<span class="token punctuation">)</span><span class="token punctuation">;</span>
		cv<span class="token double-colon punctuation">::</span><span class="token function">waitKey</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>


<span class="token keyword keyword-void">void</span> <span class="token class-name">Detector</span><span class="token double-colon punctuation">::</span><span class="token function">detect_yolox</span><span class="token punctuation">(</span><span class="token keyword keyword-const">const</span> cv<span class="token double-colon punctuation">::</span>Mat <span class="token operator">&amp;</span>image<span class="token punctuation">,</span> std<span class="token double-colon punctuation">::</span>vector<span class="token operator">&lt;</span>Detection<span class="token operator">&gt;</span><span class="token operator">&amp;</span> output<span class="token punctuation">)</span><span class="token punctuation">{</span>
	<span class="token comment">//todo</span>
<span class="token punctuation">}</span>

<span class="token keyword keyword-void">void</span> <span class="token class-name">Detector</span><span class="token double-colon punctuation">::</span><span class="token function">Dump</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>

<span class="token punctuation">}</span>


<span class="token punctuation">}</span> <span class="token comment">//namespace detector</span>
</pre><p>&#x8C03;&#x7528;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre data-role="codeBlock" data-info="cpp" class="language-cpp">Detector<span class="token double-colon punctuation">::</span>Ptr RDetector<span class="token punctuation">;</span>

<span class="token comment">// &#x521D;&#x59CB;&#x5316;&#xFF0C;&#x8BFB;&#x5165;&#x53C2;&#x6570;&#x3001;&#x6A21;&#x578B;&#x548C;&#x7C7B;&#x578B;&#x540D;</span>
<span class="token comment">// param: detectParam &#x7C7B;&#x578B;</span>
<span class="token comment">// model_path, class_path: std::string &#x7C7B;&#x578B;</span>
RDetector <span class="token operator">=</span> std<span class="token double-colon punctuation">::</span><span class="token generic-function"><span class="token function">make_unique</span><span class="token generic class-name"><span class="token operator">&lt;</span>Detector<span class="token operator">&gt;</span></span></span><span class="token punctuation">(</span>param<span class="token punctuation">,</span>model_path<span class="token punctuation">,</span>class_path<span class="token punctuation">)</span><span class="token punctuation">;</span>

<span class="token comment">//&#x8C03;&#x7528;</span>
<span class="token comment">// src &#x4E3A;&#x539F;&#x59CB;&#x56FE;&#x50CF;&#xFF0C; result &#x4E3A;&#x6309;&#x7167;&#x80FD;&#x91CF;&#x673A;&#x5173;&#x8BC6;&#x522B;&#x65B9;&#x6848;&#x4E2D;&#x89C4;&#x5B9A;&#x7684;&#x6309;&#x987A;&#x5E8F;&#x7684; 5 &#x4E2A;&#x70B9;</span>
std<span class="token double-colon punctuation">::</span>array<span class="token operator">&lt;</span>cv<span class="token double-colon punctuation">::</span>Point<span class="token punctuation">,</span><span class="token number">5</span><span class="token operator">&gt;</span> result<span class="token punctuation">;</span>
Rdetector_<span class="token operator">-&gt;</span><span class="token function">getTarget</span><span class="token punctuation">(</span>src<span class="token punctuation">,</span>result<span class="token punctuation">)</span><span class="token punctuation">;</span>
</pre><p>&#x5982;&#x679C;&#x8981;&#x6709;&#x66F4;&#x9AD8;&#x7684;&#x9002;&#x7528;&#x6027;&#xFF0C;&#x53EF;&#x4EE5;&#x8C03;&#x7528; detect_face &#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#xFF08;&#x9700;&#x8981;&#x628A;&#x5B83;&#x53D8;&#x6210;&#x516C;&#x6709;&#x58F0;&#x660E;&#x3002;&#xFF09;</p>
<p>&#x8BE5;&#x51FD;&#x6570;&#x7684;&#x4E24;&#x4E2A;&#x53C2;&#x6570;&#x5206;&#x522B;&#x662F;&#x539F;&#x59CB;&#x56FE;&#x50CF;&#x548C; Detection &#x7C7B;&#x578B;&#x7684;&#x8BC6;&#x522B;&#x7ED3;&#x679C;&#xFF08;&#x5305;&#x62EC; id &#xFF0C;&#x77E9;&#x5F62;&#x6846;&#x548C; 5 &#x70B9;&#xFF09;</p>

      </div>
      
      
    
    
    
    
    
    
    
    
  
    </body></html>